package com.little.test.client.springboot;

import com.littlerpc.proxy.proxy.RemoteClientInfo;
import com.littlerpc.proxy.proxy.RpcBeanFactoryPostProcessor;
import com.littlerpc.registry.zookeeper.ZookeeperConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by ChengPeng on 2017/6/17.
 */
@Configuration
public class RpcConfig  {


    @Bean
    public RpcBeanFactoryPostProcessor rpcBeanFactoryPostProcessor() {

        ZookeeperConfig conf = new ZookeeperConfig();
        conf.setConnectString("localhost:2181");
        conf.setTimeout(500000);

        RemoteClientInfo info = new RemoteClientInfo();
        /*
        没有zk的配置
        info.setRemotePort(9090);
        info.setRemoteHost("localhost");
        */
        //需要zk的配置
        info.setZk(true);
        info.setZkConf(conf);
        info.setProtocol("netty");
//        info.setSerializer("jackson");
        info.setSerializer("protobuf");

        RpcBeanFactoryPostProcessor rpcBeanFactoryPostProcessor = new RpcBeanFactoryPostProcessor();
        rpcBeanFactoryPostProcessor.setScanPackages(new String[]{"cn.chpeng.rpc.test.api"});
        rpcBeanFactoryPostProcessor.setRemoteClientInfo(info);
        return rpcBeanFactoryPostProcessor;
    }

}
